package com.greate.community.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * 讨论贴实体类
 * 对应数据库表 `discuss_post`
 * 用于存储论坛中的帖子信息，支持Elasticsearch搜索
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "discusspost", type = "_doc", shards = 6, replicas = 3)
public class DiscussPost {

    /**
     * 帖子ID
     */
    @Id
    private int id;

    /**
     * 发布帖子的用户ID
     */
    @Field(type = FieldType.Integer)
    private int userId;

    /**
     * 帖子标题
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String title;

    /**
     * 帖子内容
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String content;

    /**
     * 帖子类型：0-普通; 1-置顶
     */
    @Field(type = FieldType.Integer)
    private int type;

    /**
     * 帖子状态：0-正常; 1-精华; 2-拉黑
     */
    @Field(type = FieldType.Integer)
    private int status;

    /**
     * 帖子创建时间
     */
    @Field(type = FieldType.Date)
    private Date createTime;

    /**
     * 评论数量
     */
    @Field(type = FieldType.Integer)
    private int commentCount;

    /**
     * 帖子分数（用于排序）
     */
    @Field(type = FieldType.Double)
    private double score;

    // Lombok @Data注解自动生成getter和setter方法

    @Override
    public String toString() {
        return "DiscussPost{" +
                "id=" + id +
                ", userId=" + userId +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", type=" + type +
                ", status=" + status +
                ", createTime=" + createTime +
                ", commentCount=" + commentCount +
                ", score=" + score +
                '}';
    }
}
